if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.machines.schParam.SearchParameters")) {
    jsx3.lang.Class.defineClass(
            'tibco.admin.enterpriseAssets.machines.schParam.SearchParameters',
            jsx3.lang.Object, //  extends jsx3.lang.Object
            null, // does not implements any interfaces
            function(searchparams) {          //name the argument of this function
                searchparams.subscribeAll = function () {
                    searchparams.workspace = tibco.admin.Main.getServer().getJSXByName("rootLayout21C");
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.machines.search.EventID.SEARCH_PARAM_ADDED, searchparams.callgetDiscoveryConfigurations)
                    tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.machines.search.EventID.FOUND_INSTALLATIONS, searchparams.setNumberOfDiscoveredMachines)
                }

                searchparams.initialiseParam = function(dialog) {
                    var cacheDoc = tibco.admin.Main.getServer().getCache().getDocument("searchParametersCache_21C");
                    var numberOfSearches = cacheDoc.selectNodes("//record").size();
                    var newSearch = "";
                    while (++numberOfSearches) {
                        newSearch = tibco.admin.Main.getServer().getDynamicProperty("@@default_NewSearch") + (numberOfSearches);
                        if (!cacheDoc.selectSingleNode("//record[@name='" + newSearch + "']"))
                            break;
                    }
                    var textBox = dialog.getDescendantOfName("txtName_21F");
                    textBox.setBackgroundColor("#FFFFFF", true);
                    textBox.setValue(newSearch);
                    textBox.setTip("");
                }

                searchparams.setNumberOfDiscoveredMachines = function(objEvent) {
                    var pane = searchparams.workspace.getDescendantOfName("lblInstallations_21C");
                    if (pane)
                        pane.setText(objEvent.foundinstallations, true);
                }

                searchparams.callgetDiscoveryConfigurations = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/machines/schParam/rules/getDiscoveryConfigurationsRules.xml",
                            "getDiscoveryConfigurations",
                            "get discovery Configuration");
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagementDaemonEndpointURL())
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, searchparams.ongetDiscoveryConfigurationsSuccess);
                    objService.doCall();
                };

                searchparams.validateSearchTime = function() {
                    var objText = searchparams.workspace.getDescendantOfName("txtTimeout_21C");
                    return tibco.admin.util.Validation.doValidatePositiveNumbers(objText);
                }

                searchparams.ongetDiscoveryConfigurationsSuccess = function(objEvent) {
                    var matrixList = searchparams.workspace.getDescendantOfName("mtxSearchParameters_21C", true, false);
                    matrixList.repaint();
                    var cacheDoc = tibco.admin.Main.getServer().getCache().getDocument(matrixList.getXMLId());
                    if (!cacheDoc) {  //major error, handle??
                        tibco.admin.util.Log.SERVICE.error("Cache document for the search parameters list was not found.");
                    }
                    searchparams.workspace.getDescendantOfName("btnAddSearchParams21C").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                    searchparams.enableSearchButton();
                };

                searchparams.loadStartSearchPane = function(btnObj) {
                    var bottomPane = btnObj.getAncestorOfName('paneSearchStartNStop_21C');
                    return searchparams.loadSearchPane(bottomPane, "tibco/admin/enterpriseAssets/machines/schParam/ui/startDiscovery.xml");
                }

                searchparams.loadStopSearchPane = function(btnObj) {
                    tibco.admin.util.Log.RESOURCES.trace("loading stop pane");
                    var bottomPane = btnObj.getAncestorOfName('paneSearchStartNStop_21C');
                    return searchparams.loadSearchPane(bottomPane, "tibco/admin/enterpriseAssets/machines/schParam/ui/stopDiscovery.xml")
                }

                searchparams.loadSearchPane = function(domNode, strURL) {
                    domNode.removeChildren();
                    return tibco.admin.Main.loadUIResource(domNode, "tibco.admin", strURL, true);
                }

                searchparams.enableSearchButton = function(checkBox) {
                    var searchButton = searchparams.workspace.getDescendantOfName('btnSearch_21C');
                    var removeButton = searchparams.workspace.getDescendantOfName('btnRemoveParams21C');
                    if ((checkBox != null) && (checkBox.getChecked() == jsx3.gui.CheckBox.CHECKED)) {
                        if (searchButton.getEnabled() == jsx3.gui.Form.STATEDISABLED) searchButton.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                        if (removeButton != null) {
                            if (removeButton.getEnabled() == jsx3.gui.Form.STATEDISABLED) removeButton.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                        }
                    } else {
                        var mtxList = searchparams.workspace.getDescendantOfName('mtxSearchParameters_21C');
                        var cacheDoc = mtxList.getXML();
                        if (cacheDoc.getRootNode().selectNodes("//record").getLength() == 0 ||
                            cacheDoc.selectNodes("//record[@checked='1']").getLength() == 0) { //no records
                            searchButton.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                            removeButton.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                        } else {
                            searchButton.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                            removeButton.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                        }
                    }
                }

                searchparams.callstartDiscovery = function(btnObj) {
                    if (searchparams.validateSearchTime()) {
                        var objService = tibco.admin.Main.loadService("tibco.admin",
                                "tibco/admin/enterpriseAssets/machines/schParam/rules/startDiscoveryRules.xml",
                                "startDiscovery",
                                "start discovery");
                        objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagementDaemonEndpointURL())
                        searchparams.bottomPane = btnObj.getAncestorOfName('paneSearchStartNStop_21C');
                        objService.subscribe(jsx3.net.Service.ON_SUCCESS, searchparams.onstartDiscoverySuccess);
                        objService.doCall();
                    }
                };

                searchparams.onstartDiscoverySuccess = function(objEvent) {
                    // set the operation handler
                    searchparams.operationHandler = objEvent.target.operationHandler;
                    // Load stop pane
                    var stopPane = searchparams.loadSearchPane(searchparams.bottomPane, "tibco/admin/enterpriseAssets/machines/schParam/ui/stopDiscovery.xml")
                    // Set the time out for stop pane
                    stopPane.getDescendantOfName("lblTimeOut_21C").setText(objEvent.target.timeout, true)
                    stopPane.getDescendantOfName("lblInstallations_21C").setText("0", true);
                    searchparams.workspace.getDescendantOfName("btnRemoveParams21C").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    // send a message to resourcesSearchforinstallations to disable its close btn.
                    var msg0 = new Object();
                    msg0.subject = tibco.admin.enterpriseAssets.machines.search.EventID.DISABLE_CLOSE_SEARCH;
                    tibco.admin.PubSub.publish(msg0);
                    // Send a message for discovered installation to cleare its cache
                    var msg1 = new Object();
                    msg1.subject = tibco.admin.enterpriseAssets.machines.search.EventID.ON_CLEAR_CACHE;
                    tibco.admin.PubSub.publish(msg1);

                    // send  a message to discoverd installation  for getting discoverd installations
                    var msg = new Object();
                    msg.subject = tibco.admin.enterpriseAssets.machines.search.EventID.ON_SET_DETAILS;
                    msg.operationHandler = searchparams.operationHandler;
                    // publish this message now and every 5 seconds
                    tibco.admin.PubSub.publish(msg);
                    // Set the interval.
                    var count = 1
                    searchparams.discoveryInterval = setInterval(function() {
                        stopPane.getDescendantOfName("lblElapsedTime_21C").setText((count * 5), true)
                        count++;
                        tibco.admin.util.Log.RESOURCES.trace("Publishing messsage:\n#########################################################\n" + msg.toString() + "\n ");
                        tibco.admin.PubSub.publish(msg);
                        tibco.admin.util.Log.RESOURCES.trace("Message Published");
                        // update the time elapsed

                    }, 5000);
                    setTimeout(function() {
                        searchparams.stopDiscovery()
                    }, window.parseInt(objEvent.target.timeout) * 1000);

                    //  }
                };


                searchparams.stopDiscovery = function() {
                    tibco.admin.util.Log.RESOURCES.trace("Clearing the time interval");
                    // Cleare interval
                    window.clearInterval(searchparams.discoveryInterval);
                    // Ask server to stop discovey
                    searchparams.callstopDiscovery(searchparams.operationHandler);
                    // Load the satrt pane
                    searchparams.loadSearchPane(searchparams.bottomPane, "tibco/admin/enterpriseAssets/machines/schParam/ui/startDiscovery.xml");
                    // send a message to resourcesSearchforinstallations to enable its close btn.
                    var msg0 = new Object();
                    msg0.subject = tibco.admin.enterpriseAssets.machines.search.EventID.ENABLE_CLOSE_SEARCH;
                    tibco.admin.PubSub.publish(msg0);
                }

                searchparams.callstopDiscovery = function(operationHandler) {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/machines/schParam/rules/stopDiscoveryRules.xml",
                            "stopDiscovery",
                            "stop discovery");
                    objService.operationHandler = operationHandler;
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagementDaemonEndpointURL());
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, searchparams.onstopDiscoverySuccess);
                    objService.doCall();
                };

                searchparams.onstopDiscoverySuccess = function(objEvent) {
                    searchparams.workspace.getDescendantOfName("btnRemoveParams21C").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                };

                //call this method to begin the service call (eg.searchparams.callremoveDiscoveryConfigurations();)
                searchparams.callremoveDiscoveryConfigurations = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin",
                            "tibco/admin/enterpriseAssets/machines/schParam/rules/removeDiscoveryConfigurationsRules.xml",
                            "removeDiscoveryConfigurations",
                            "remove discovery configuration");

                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getManagementDaemonEndpointURL());
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, searchparams.onremoveDiscoveryConfigurationsSuccess);
                    objService.subscribe(jsx3.net.Service.ON_ERROR, searchparams.onremoveDiscoveryConfigurationsError);
                    objService.subscribe(jsx3.net.Service.ON_INVALID, searchparams.onremoveDiscoveryConfigurationsInvalid);
                    objService.doCall();
                };

                searchparams.onremoveDiscoveryConfigurationsSuccess = function(objEvent) {
                    searchparams.callgetDiscoveryConfigurations();

                    //    }
                };

                searchparams.onremoveDiscoveryConfigurationsError = function(objEvent) {    //removedDiscoveryConfigurationCache_21C
                };

                searchparams.onremoveDiscoveryConfigurationsInvalid = function(objEvent) {
                    tibco.admin.util.ServiceHelper.logInvalid(objEvent, "SearchParameters", "removeDiscoveryConfigurations")
                };


                searchparams.onSelectAll = function() {
                    var button = tibco.admin.Main.getServer().getJSXByName('btnSearch_21C');
                    var button2 = tibco.admin.Main.getServer().getJSXByName('btnDelete');
                    var mtx = tibco.admin.Main.getServer().getJSXByName("mtxSearchParameters_21C");
                    mtxCache = mtx.getXML();
                    var mycollection = mtxCache.selectNodes("//record");
                    if (mycollection.getLength() > 0) {
                        button.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                        button2.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                    }
                    while (mycollection.hasNext()) {
                        mycollection.next().setAttribute("checked", "1");
                    }
                    mtx.repaintData();
                }

                searchparams.onDeselectAll = function() {
                    var button = tibco.admin.Main.getServer().getJSXByName('btnSearch_21C');
                    var button2 = tibco.admin.Main.getServer().getJSXByName('btnDelete');
                    button.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    button2.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                    var mtx = tibco.admin.Main.getServer().getJSXByName("mtxSearchParameters_21C");
                    mtxCache = mtx.getXML();
                    var mycollection = mtxCache.selectNodes("//record");
                    while (mycollection.hasNext()) {
                        mycollection.next().setAttribute("checked", "0");
                    }
                    mtx.repaint();
                }
            }
            )
            ;
}
